package com.broada.apm.proxy;

import java.lang.reflect.Method;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * cglib 方法代理
 * @author jianfei.xu
 * @date   2016年3月28日
 *
 */
public class ThriftControllerMethodIntercept implements MethodInterceptor {
	private Object realObj; //真实对象
	
	public ThriftControllerMethodIntercept(Object realObj) {
		super();
		this.realObj = realObj;
	}


	@Override
	public Object intercept(Object proxy, Method method, Object[] args, MethodProxy arg3) throws Throwable {
		try {
			return method.invoke(realObj, args);
		} catch (Exception e) {
			LOG.error(proxy.getClass().getName() + "." + method.getName() + "调用出现异常：", e);
		}
		
		return null;
	}

	private static Logger LOG = LoggerFactory.getLogger(ThriftControllerMethodIntercept.class);
	
}
